* Clean test scores

* Extract single cognitive ability factor
factor math_7 reading_7 math_11 reading_11 generalab_11, factor(1) 


mat FactorLoadings=e(L)
mat Eigenvalues=e(Ev)
predict iCogAbility, bartlett 
egen CogAbility=std(iCogAbility)
drop iCogAbility

ge BCogAbility=CogAbility>0
replace BCogAbility=. if CogAbility==.

* standardized test scores at age 7
local vars math reading
foreach v of local vars {
egen `v'_sd_7=std(`v'_7)
}

* standardized test scores at age 11
local vars nonverbal verbal generalab reading math 
foreach v of local vars {
egen `v'_sd_11=std(`v'_11)
}
